home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_2 / fix2dim.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  627 b   |  21 lines  |  [MATF/MATL]

  1. function [P0,err,P] = fix2dim(G,P0,delta,max1)
  2. % [P0,err] = fix2dim(G,P0,delta,max1)
  3. % [P0,err,P] = fix2dim(G,P0,delta,max1)
  4. % Fixed point iteration for higher dimensions.
  5. % G is the vector function, input.
  6. % P0 is the starting vector, input.
  7. % delta is the tolerance for P0, input.
  8. % max1 is the maximum number of iterations, input.
  9. % P0 is the vector fixed point, output.
  10. % err is the error estimate for P0, output.
  11. % P  is the matrix of iterations, output.
  12. P = P0;
  13. for k=1:max1,
  14.   P1 = feval(G,P0);
  15.   P = [P;P1];
  16.   err = norm(P1-P0);
  17.   relerr = err/(norm(P1)+eps);
  18.   P0 = P1;
  19.   if (err<delta)|(relerr<delta), break, end
  20. end
  21.